/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.mwas.proteana.geneontology.util;

import pl.mwas.proteana.geneontology.GOTermBuilder;

/**
 *
 * @author mateusz.was
 */
public class GoTermPropertyFactory {
    public GOTermBuilder addPropertyTo(GOTermBuilder term, String property) {
        
        String prefix = grepPrefix(property);
        String body = grepBody(property);
        String comment = grepComment(property);

        switch (prefix) {
            case "id":
                term.setId(body);
                break;
            case "name":
                term.setName(body);
                break;
            case "namespace":
                term.setNamespace(body);
                break;
            case "is_anonymous":
                term.setIsAnonymous(true);
                break;
            case "alt_id":
                term.setAltId(body);
                break;
            case "def":
                term.setDef(body);
                break;
            case "comment":
                term.setComment(body);
                break;
            case "subset":
                term.setSubset(body);
                break;
            case "synonym":
                term.setSynonym(body);
                break;
            case "xref":
                term.setXRef(body);
                break;
            case "is_a":
                term.setRelationship("is_a " + body);
                break;
            case "intersection_of":
                term.setRelationship("intersection_of " + body);
                break;
            case "union_of":
                //term.setRelationship("union_of " + body);
                break;
            case "disjoint_from":
                //term.setRelationship("disjoint_from " + body);
                break;
            case "relationship":
                term.setRelationship(body);
                break;
            case "is_obsolete":
                term.setIsObsolete(true);
                break;
            case "replaced_by":
                term.setReplacedBy(body);
                break;
            case "consider":
                term.setConsider(body);
                break;
            case "created_by":
                term.setCreatedBy(body);
                break;
            case "creation_date":
                term.setCreationDate(body);
                break;
        }
        
        
        
        return term;
    }
    
    private String grepPrefix(String line) {
        return line.substring(0, line.indexOf(":")).trim();
    }

    private String grepBody(String line) {
        if (line.contains("\"")) {
            return line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")).trim();
        } else if (line.contains("!")) {
            return line.substring(line.indexOf(":") + 1, line.lastIndexOf("!")).trim();
        } else {
            return line.substring(line.indexOf(":") + 1).trim();
        }
    }

    private String grepComment(String line) {
        if (line.contains("!")) {
            return line.substring(line.lastIndexOf("!")).trim();
        } else {
            return null;
        }
    }
}
